<wxs src="../../wxcomponents/public/publicFun.wxs" module="publicFun"></wxs>
<template>
<view>
<view class="container">
  <view class="fx_head" :style="'height:' + (fxCenter.userLevel==0?'380rpx':'306rpx')+';background:'+ setting.platformSetting.defaultColor">
    <view class="fx_user_info">
      <image class="fx_head_img" :style="'background:'+ setting.platformSetting.secondColor" data-link="pre_change_user_info.html" @tap="tolinkUrl" v-if="loginUser&&loginUser.platformUser" :src="loginUser.platformUser.headimgurl||'https://image1.sansancloud.com/zhihuishangwu/2019_12/5/11/8/56_403.jpg?x-oss-process=style/preview_120'"></image>
      <image class="fx_head_img" :style="'background:'+ setting.platformSetting.secondColor" data-link="login.html?url=fx_center.html" @tap="tolinkUrl" v-else src="https://image1.sansancloud.com/zhihuishangwu/2019_12/5/11/8/56_403.jpg?x-oss-process=style/preview_120"></image>
      <view class="fx_user_base">
        <text class="fx_user_name" data-link="pre_change_user_info.html" @tap="tolinkUrl" v-if="loginUser&&loginUser.platformUser">{{fxCenter.nickname||fxCenter.bindTelno}}</text>
        <text class="fx_user_name" v-else  data-link="login.html?url=fx_center.html" @tap="tolinkUrl">登录/注册</text>
        <view class="fx_tuijian" v-if="loginUser&&loginUser.platformUser&&loginUser.platformUser.parentId">
            <text class="tui">推</text>
            <text class="fx_tuijian_telno_img" v-if="loginUser.platformUser.parentTelno" :data-phonenumber="loginUser.platformUser.parentTelno" @tap="calling">联系他</text>
            <text style="font-size: 24rpx;margin-left: 10rpx;">{{loginUser.platformUser.parentName}}</text>
        </view>
        <view style="display: flex;">
            <!-- setting.platformSetting.secondColor -->
            <view class="fx_user_parentPlatformUser" :style="'background:rgba(255,255,255,0.4)'" :data-link="fxState?'level_detail.html?id='+myMembers.id:''" @tap='tolinkUrl'>
              <image class="fx_recommend_icon" v-if="fxState" src="https://image1.sansancloud.com/zhihuishangwu/2019_11/15/22/51/10_91.jpg?x-oss-process=style/preview_120"></image>
              <text :style="'color:' + (fxState?'#FFD854':'#fff')">{{fxCenter.userLevelName||'普通用户'}}</text>
            </view> 
        </view>
      </view>
    </view>
    <!-- <view class="fx_data_center">
      <view class="fx_data_item" data-link="month_group_income_page.html?needLogin=1" @tap="tolinkUrl">
        <text class="fx_data_value">￥{{fxDetail.curMonthGroupPayed?publicFun.toFix(fxDetail.curMonthGroupPayed):0}}</text>
        <text class="fx_data_title">本月间推交易额</text>
      </view>
      <view class="interval_line"></view>
      <view class="fx_data_item" data-link="month_income_page.html?needLogin=1" @tap="tolinkUrl">
        <text class="fx_data_value">￥{{fxDetail.curMonthDirectProfit?publicFun.toFix(fxDetail.curMonthDirectProfit):0}}</text>
        <text class="fx_data_title">本月小区直推收益</text>
      </view>
      <view class="interval_line"></view>
      <view class="fx_data_item" data-link="month_income_page.html?needLogin=1" @tap="tolinkUrl">
        <text class="fx_data_value">￥{{fxDetail.curMonthGroupProfit?publicFun.toFix(fxDetail.curMonthGroupProfit):0}}</text>
        <text class="fx_data_title">本月大区间推收益</text>
      </view>
    </view> -->
    <view class="fx_data_center">
      <view class="fx_data_item" data-link="month_income_page.html?needLogin=1" @tap="tolinkUrl">
        <text class="fx_data_value">￥{{fxDetail.totalProfit?publicFun.toFix(fxDetail.totalProfit):0}}</text>
        <text class="fx_data_title">已实现收益</text>
      </view>
      <view class="interval_line"></view>
      <view class="fx_data_item" data-link="month_group_income_page.html?needLogin=1" @tap="tolinkUrl">
        <text class="fx_data_value">￥{{fxDetail.unrealizedProfit?publicFun.toFix(fxDetail.unrealizedProfit):0}}</text>
        <text class="fx_data_title">未实现收益</text>
      </view>
     <view class="interval_line"></view>
      <view class="fx_data_item"  data-link="tixian_list.html?needLogin=1"  @tap="tolinkUrl">
        <text class="fx_data_value">￥{{fxDetail.totalProfit?publicFun.toFix(fxDetail.totalProfit-fxDetail.totalTixian):0}}</text>
        <text class="fx_data_title">佣金余额</text>
      </view> 
    </view>
    <block v-if="fxCenter&&fxCenter.userLevel>0">
        <view class="fx_recommend_btn_bg"></view>
        <view class="fx_recommend_btn" @tap="showPoster">
          <image class="fx_recommend_icon" src="https://image1.sansancloud.com/xianhua/2019_11/15/19/1/47_890.jpg?x-oss-process=style/preview_120"></image>
          <text class="fx_recommend_text">推广码</text>
        </view>
    </block>
    <!--  #ifdef MP -->
    <view class='fx_recommend_btn_bg ewm' v-if="loginUser"></view>
    <view class='fx_recommend_btn ewm' @tap='clickWxGz' v-if="loginUser&&loginUser.platformUser&&!loginUser.platformUser.openid" >
      <image class='fx_recommend_icon' src='https://image1.sansancloud.com/zhihuishangwu/2019_11/21/16/20/28_464.jpg?x-oss-process=style/preview_120'></image>
      <text class='fx_recommend_text'>绑定号</text>
    </view>
    <view class='fx_recommend_btn ewm' @tap='clickWxGz' v-if="loginUser&&loginUser.platformUser&&loginUser.platformUser.openid">
      <image class='fx_recommend_icon' src='https://image1.sansancloud.com/zhihuishangwu/2019_11/21/16/22/22_495.jpg?x-oss-process=style/preview_120'></image>
      <text class='fx_recommend_text'>解绑号</text>
    </view>
    <!--  #endif -->
    <view class="user_level_card" v-if="fxCenter.userLevel==0">
      <view class="user_level_card_left">
        <text>普通用户</text>
      </view>
      <view class="user_level_card_right" @tap="showPoster">
        <text>分享成为超级会员</text>
        <image src="https://image1.sansancloud.com/xianhua/2019_11/15/17/23/46_208.jpg?x-oss-process=style/preview_120" class="user_level_card_right_icon"></image>
      </view>
    </view>
  </view>
  <!-- 资金池列表 -->
  <view class="pool_profit_block" v-if="showPoolProfitList.length!=0&&!updateState" :style="'height:'+showHeight" >
      <view class="pool_profit_list">
          <view class="pool_profit_item">
              <view class="pool_profit_content">
                  <text class="pool_profit_content_item" style="width: 30%;">{{showPoolProfitList[0].tongjiTargetName}}</text>
                  <text class="pool_profit_content_item center" style="width: 20%;">{{showPoolProfitList[0].year}}-{{showPoolProfitList[0].month}}</text>
                  <text class="pool_profit_content_item end" style="width: 50%;">共享分润￥{{showPoolProfitList[0].monthAmount}}</text>
              </view>
          </view>
      </view>
  </view>
  <view class="pool_profit_block" :style="'height:'+showHeight" v-if="showPoolProfitList.length!=0&&updateState">
      <swiper class="pool_profit_list" :current="swiperIndex" :style="'height:'+showHeight" skip-hidden-item-layout='true' :display-multiple-items="showCount" :indicator-dots="false" autoplay="true" interval="5000" duration="500" vertical='true'>
          <swiper-item class="pool_profit_item" v-for="(item,index) in showPoolProfitList" :key="index" v-if="item.showState==1">
              <view class="pool_profit_content">
                  <text class="pool_profit_content_item" style="width: 30%;">{{item.tongjiTargetName}}</text>
                  <text class="pool_profit_content_item center" style="width: 20%;">{{item.year}}-{{item.month}}</text>
                  <text class="pool_profit_content_item end" style="width: 50%;">共享分润￥{{item.monthAmount}}</text>
              </view>
          </swiper-item>
      </swiper>
      <view class="pool_profit_icon_blcok" @click="showPoolProfitFun">
          <!-- 下 -->
          <image v-if="!showState" class="pool_profit_icon" src="https://image1.sansancloud.com/xianhua/2020_2/27/18/34/10_820.jpg?x-oss-process=style/preview_120"></image>
          <!-- 上 -->
          <image v-else class="pool_profit_icon" src="https://image1.sansancloud.com/xianhua/2020_2/27/18/34/10_788.jpg?x-oss-process=style/preview_120"></image>
      </view>
  </view>
  <view class="community_data_block">
    <view class="community_data_item" data-link="fx_users.html?relateType=directChildren&needLogin=1" @tap="tolinkUrl">
      <image src="https://image1.sansancloud.com/xianhua/2020_3/9/20/14/2_794.jpg?x-oss-process=style/preview_120" :style="'background:'+ setting.platformSetting.defaultColor" class="community_data_item_icon"></image>
      <view class="community_data_item_info">
        <text class="community_data_item_title">直推人数</text>
        <view class="community_data_item_value">
          <text class="community_data_item_value_data">{{fxDetail.directChildren||0}}</text>
          <text class="community_data_item_value_unit">人</text>
        </view>
      </view>
    </view>
    <view class="community_data_item" data-link="fx_users.html?relateType=groupChildren&needLogin=1" @tap="tolinkUrl">
      <image src="https://image1.sansancloud.com/xianhua/2020_3/9/20/4/49_10.jpg?x-oss-process=style/preview_120" :style="'background:'+ setting.platformSetting.defaultColor" class="community_data_item_icon"></image>
      <view class="community_data_item_info">
        <text class="community_data_item_title">间推人数</text>
        <view class="community_data_item_value">
          <text class="community_data_item_value_data">{{fxDetail.groupChildren||0}}</text>
          <text class="community_data_item_value_unit">人</text>
        </view>
      </view>
    </view>
  </view>
  <view class="total_score_block">
    <text class="total_score_title">总{{properties.alias_yongjin||'积分'}}收益</text>
    <view class="total_score_data">
      <view class="total_score_data_one">
        <view class="total_score_data_one_item" data-link="month_income_page.html?needLogin=1" @tap="tolinkUrl">
          <text class="total_score_data_one_item_title">直推收益</text>
          <view class="total_score_data_one_item_value">
            <text class="total_score_data_one_item_data">{{fxDetail.directTotalProfit?publicFun.toFix(fxDetail.directTotalProfit):0}}</text>
            <image class="total_score_data_one_item_icon" src="https://image1.sansancloud.com/xianhua/2019_11/15/18/12/32_731.jpg?x-oss-process=style/preview_120"></image>
          </view>
        </view>
        <view class="total_score_data_one_item" data-link="month_income_page.html?needLogin=1" @tap="tolinkUrl">
          <text class="total_score_data_one_item_title">间推收益</text>
          <view class="total_score_data_one_item_value">
            <text class="total_score_data_one_item_data">{{publicFun.toNum(fxDetail.groupTotalProfit)?publicFun.toFix(publicFun.toNum(fxDetail.groupTotalProfit)):0}}</text>
            <image class="total_score_data_one_item_icon" src="https://image1.sansancloud.com/xianhua/2019_11/15/18/12/32_731.jpg?x-oss-process=style/preview_120"></image>
          </view>
        </view>
      </view>
      <view class="total_score_data_two">
        <view class="total_score_data_two_item" data-link="tixian_list.html?needLogin=1" @tap="tolinkUrl">
          <text class="total_score_data_two_item_title">已发放金额</text>
          <text class="total_score_data_two_item_value">{{fxDetail.totalTixian?publicFun.toFix(fxDetail.totalTixian):0}}{{properties.alias_yongjin||'积分'}}</text>
        </view>
        <view class="interval_line" style="background:#f1f1f1;opacity:1"></view>
        <view class="total_score_data_two_item" data-link="month_income_page.html?needLogin=1" @tap="tolinkUrl">
          <text class="total_score_data_two_item_title">团队营业额</text>
          <text class="total_score_data_two_item_value">{{publicFun.toNum(fxDetail.groupTotalProfit)?publicFun.toFix(publicFun.toNum(fxDetail.groupTotalProfit)):0}}{{properties.alias_yongjin||'积分'}}</text>
        </view>
      </view>
    </view>
  </view>
  <!-- 推广中心 -->
  <view class="fx_recommend_center_extra">
    <view class="fx_recommend_item" data-link="custom_page_fenxiaoshuoming.html" @tap="tolinkUrl">
      <view class="fx_recommend_info">
        <image :style="'background:'+ setting.platformSetting.defaultColor" class="fx_recommend_item_icon" src="https://image1.sansancloud.com/xianhua/2020_3/9/19/54/55_437.jpg?x-oss-process=style/preview_120"></image>
        <text class="fx_recommend_item_text">推广计划书</text>
      </view>
      <image class="fx_recommend_item_link" src="https://image1.sansancloud.com/xianhua/2019_1/15/16/33/5_514.jpg"></image>
    </view>
    <view class="fx_recommend_item" data-link="user_bank_info_setting.html?needLogin=1" @tap="tolinkUrl">
      <view class="fx_recommend_info">
        <image :style="'background:'+ setting.platformSetting.defaultColor" class="fx_recommend_item_icon" src="https://image1.sansancloud.com/xianhua/2020_3/9/19/54/55_429.jpg?x-oss-process=style/preview_120"></image>
        <text class="fx_recommend_item_text">银行卡信息</text>
      </view>
      <image class="fx_recommend_item_link" src="https://image1.sansancloud.com/xianhua/2019_1/15/16/33/5_514.jpg"></image>
    </view>
    <!-- <view class="fx_recommend_item" data-link="yijian_fankui.html?needLogin=1" @tap="tolinkUrl">
      <view class="fx_recommend_info">
        <image class="fx_recommend_item_icon" src="https://image1.sansancloud.com/xianhua/2019_11/15/18/42/52_887.jpg?x-oss-process=style/preview_120"></image>
        <text class="fx_recommend_item_text">意见反馈</text>
      </view>
      <image class="fx_recommend_item_link" src="https://image1.sansancloud.com/xianhua/2019_1/15/16/33/5_514.jpg"></image>
    </view>
    <view class="fx_recommend_item" data-link="form_chain_detail.html?chainId=9&needLogin=1" @tap="tolinkUrl">
      <view class="fx_recommend_info">
        <image class="fx_recommend_item_icon" src="https://image1.sansancloud.com/xianhua/2019_11/15/18/42/52_882.jpg?x-oss-process=style/preview_120"></image>
        <text class="fx_recommend_item_text">预约</text>
      </view>
      <image class="fx_recommend_item_link" src="https://image1.sansancloud.com/xianhua/2019_1/15/16/33/5_514.jpg"></image>
    </view> -->
    <view class="fx_recommend_item" data-link="custom_page_xiaohu.html" @tap="tolinkUrl">
      <view class="fx_recommend_info">
        <image :style="'background:'+ setting.platformSetting.defaultColor" class="fx_recommend_item_icon" src="https://image1.sansancloud.com/xianhua/2020_3/9/19/54/55_432.jpg?x-oss-process=style/preview_120"></image>
        <text class="fx_recommend_item_text">注销账户</text>
      </view>
      <image class="fx_recommend_item_link" src="https://image1.sansancloud.com/xianhua/2019_1/15/16/33/5_514.jpg"></image>
    </view>
    <!--  #ifdef MP-WEIXIN -->
    <button class="fx_recommend_item" open-type='getPhoneNumber' @getphonenumber="getPhoneNumber" v-if="(loginUser&&!loginUser.platformUser.bindTelno)||!loginUser">
      <view class="fx_recommend_info">
        <image :style="'background:'+ setting.platformSetting.defaultColor" class="fx_recommend_item_icon" src="https://image1.sansancloud.com/xianhua/2020_3/9/19/54/55_408.jpg?x-oss-process=style/preview_120"></image>
        <text class="fx_recommend_item_text">绑定手机号</text>
      </view>
      <view class="fx_recommend_right">
          <text style="margin-right:10rpx;color: #0089FF;">去绑定</text>
          <image class="fx_recommend_item_link" src="https://image1.sansancloud.com/xianhua/2019_1/15/16/33/5_514.jpg"></image>
      </view>
    </button>
    <view class="fx_recommend_item" @tap="tipTelnoFun" v-else>
      <view class="fx_recommend_info">
        <image :style="'background:'+ setting.platformSetting.defaultColor" class="fx_recommend_item_icon" src="https://image1.sansancloud.com/xianhua/2020_3/9/19/54/55_408.jpg?x-oss-process=style/preview_120"></image>
        <text class="fx_recommend_item_text">绑定手机号</text>
      </view>
      <view class="fx_recommend_right">
          <text style="margin-right:10rpx">已绑定手机号</text>
          <image class="fx_recommend_item_link" src="https://image1.sansancloud.com/xianhua/2019_1/15/16/33/5_514.jpg"></image>
      </view>
    </view>
    <!--  #endif -->
  </view>
  <!--  #ifdef APP-PLUS -->
  <view class="login_out" v-if="loginUser">
    <button class='login_out_btn' @tap='loginOut' :style='"color:"+setting.platformSetting.defaultColor+";border:1px solid "+setting.platformSetting.defaultColor'>退出登录</button>
  </view>
  <!--  #endif -->
</view>
<posters-user-info-component :ewmImgUrl="ewmImgUrl" v-if="posterState" @closePoaster="getChilrenPoster"></posters-user-info-component>
<custom-page-index-component id="container" :receiveData="sendIndexData" v-if="sendIndexData" @refreshFun="getRefreshFun"></custom-page-index-component> 
</view>
</template>

<script>

export default {
  data() {
    return {
      setting: {},
      fxCenter: {},
      fxState: false,
      loginUser: null,
      fxDetail: {},
      wsState: false,
      posterState: false,
      updateState:true,
      ewmImgUrl: "",
      swiperIndex:0,
      sendFormData: null,
      fxLevel: "",
      conut:1,
      properties: "",
      showPopup:false,
      sendIndexData:null,
      poolProfitList:[],
      showPoolProfitList:[],
      showState:false,
      showHeight:"55rpx",
      showCount:1,
      maxCount:1,
      myMembers:null,
    };
  },
  props: {},
  onTabItemTap:function(e){
      console.log("===onTabItemTap===",e)
  },
  onLoad: function () {
    let that = this;
    let loginUser=getApp().globalData.loginUser||null;
    let sendIndexData = JSON.stringify({ title: 'noTitle', url: "fxCenter", params: {} })
    that.setData({ sendIndexData: sendIndexData })
    console.log("getApp().globalData.loginUser",loginUser)
    if (loginUser) {
      that.checkState();
    } else {
      getApp().globalData.addLoginListener(that);
      // getApp().globalData.showToastLoading('loading', true);
      // console.log("====setTimeout1=====");
      // that.setTimeoutLogin(that.conut);
    }
  },
  onReady: function () {
      wx.setNavigationBarTitle({
        title: "分销中心"
      });
  },
  onShow: function () {
      let that=this;
      getApp().globalData.addAuthorizationListenerItem(that)
      that.getSessionUserInfo();
      that.setData({
        setting: getApp().globalData.setting,
        properties: getApp().globalData.properties
      });
  },

  onHide: function () {},

  onUnload: function () {},
  onPullDownRefresh: function () {
    let that = this;
    that.getSessionUserInfo();
    if (getApp().globalData.loginUser) {
      that.checkState();
    } else {
      getApp().globalData.addLoginListener(that); 
      // getApp().globalData.showToastLoading('loading', true);
      // that.setTimeoutLogin(that.conut);
    }
    wx.stopPullDownRefresh();
  },
  onReachBottom: function () {},
  onShareAppMessage: function () {
    return getApp().globalData.shareForFx2(getApp().globalData.miniIndexPage);
  },
  methods: {
    getRefreshFun:function(){
        let that=this;
        that.getSessionUserInfo();
        if (getApp().globalData.loginUser) {
          that.checkState();
        } else {
          getApp().globalData.addLoginListener(that); 
          // getApp().globalData.showToastLoading('loading', true);
          // that.setTimeoutLogin(that.conut);
        }
    },
    showPoolProfitFun:function(){
        let that=this;
        // that.swiperIndex=0;
        that.setData({swiperIndex:0})
        if(!that.showState){
            that.setData({updateState:false})
        }
        console.log("==that.swiperIndex==",that.swiperIndex)
        setTimeout(function(){
            if(!that.showState){
                that.setData({updateState:true})
                that.showHeight=that.maxCount<10?(55*that.maxCount)+'rpx':'550rpx';
                that.showCount=that.maxCount<10?that.maxCount:10
            }else{
                that.showHeight='55rpx'
                that.showCount=1;
            }
            that.setData({showState:!that.showState})
            console.log("==showHeight===",that.showHeight)
        },100)
    },
    getStateData: function (state) {
      let that = this;
      console.log("===getStateData===", state);
      that.selectComponent("#container").setPopupState(state);
    },
    tipTelnoFun:function(){
        let that=this;
        let loginUser = that.loginUser;
        getApp().globalData.consoleFun('===tipTelnoFun===');
        wx.showModal({
          title: '已绑定',
          showCancel:false,
          content: "您已绑定了"+loginUser.platformUser.bindTelno,
          success (res) {
            if (res.confirm) {
              console.log('用户点击确定')
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
    },
    getPhoneNumber:function(e){
        let that=this;
        getApp().globalData.consoleFun('===getPhoneNumber===',[e]);
        let resutlData=e.detail;
        if(!resutlData.encryptedData){
            return
        }
        let params={
            encryptedData:decodeURIComponent(resutlData.encryptedData),
            iv:decodeURIComponent(resutlData.iv),
            forceBind:1,
            scene:getApp().globalData.more_scene||0
        }
        let customIndex = getApp().globalData.AddClientUrl("/decode_phone.html", params, 'post'); //拿custom_page
        console.log("customIndex",customIndex)
        uni.request({
            url: customIndex.url,
            data: customIndex.params,
            method: 'POST',
            header: getApp().globalData.headerPost,
            success: function (res) {
              console.log("====== res.data=========", res.data);
              let showToastData={
                  text:'绑定成功!',
                  type:'success'
              }
              if (!res.data.errcode || res.data.errcode == '0') {
                  that.getSessionUserInfo()
              } else {
                showToastData={
                    text:'绑定失败!',
                    type:'',
                    image:'/wxcomponents/images/icons/tip.png'
                }
              };
              getApp().globalData.showToastFun(showToastData.text,1000,showToastData.type,showToastData.image)
            },
            fail:function(){
                getApp().globalData.showToastFun("绑定失败!",1000,'','/wxcomponents/images/icons/tip.png')
            },
        })
    },
    /* 退出登录 */
    loginOut: function () {
      getApp().globalData.showToastLoading('loading', true);
      getApp().globalData.loginOut("/logout.html")
    },
      clickWxGz: function () {
        let that = this;
        console.log('===bindWxGz====', that.loginUser)
        let loginUser = that.loginUser;
        let title = "你确定要绑定公众号推送嘛~"
        if (loginUser.platformUser.openid) {
          title = "你确定要解绑公众号推送嘛~"
        }
        wx.showModal({
          title: '提示',
          content: title,
          success: function (res) {
            if (res.confirm) {
              if (!loginUser.platformUser.openid) {
                that.bindWxGz()
              } else {
                that.unBindWxGz()
              }
            } else if (res.cancel) {

            }
          }
        })
      },
      bindWxGz: function () {
        let that = this;
        let paramsUrl = "https://mini.sansancloud.com/chainalliance/" + getApp().globalData.clientNo + "/bindWxGz.html?platformUserId=" + that.loginUser.platformUser.id;
        that.tolinkUrl(paramsUrl)
        that.getSessionUserInfo();
      },
      unBindWxGz: function () {
        let that = this
        let customIndex = getApp().globalData.AddClientUrl("/wx_unbind_wx_gz_openid.html")
        //拿custom_page
        wx.request({
          url: customIndex.url,
          header: getApp().globalData.header,
          success: function (res) {
            console.log("====== res.data=========", res.data)
            wx.hideLoading()
            if (!res.data.errcode || res.data.errcode == '0') {
              wx.showToast({
                title: '解绑成功~',
                icon: 'success',
                duration: 1000
              })
              that.getSessionUserInfo();
            } else {
              console.log('加载失败')
              wx.showToast({
                title: res.data.errMsg + '~',
                image: '/wxcomponents/images/icons/tip.png',
                duration: 1000
              })
            }
          },
          fail: function (res) {
            console.log(res)
            wx.hideLoading()
          }
        })
      },
    /* 组件事件集合 */
    tolinkUrl: function (e) {
	  console.log("tolinkUrl",e)
      let linkUrl = e.currentTarget?e.currentTarget.dataset.link:e;
      getApp().globalData.linkEvent(linkUrl);
    },
    get_fxLevelFun: function (setting) {
      let fxLevel = setting.platformSetting.fxLevel;

      if (!fxLevel) {
        fxLevel = 0;
      }
      this.setData({
        fxLevel: fxLevel
      });
    },
    //获取推广中心，查看是否有资格
    get_fx_centerFun: function (setting) {
      console.log('-------推广中心--------', setting);
      var customIndex = getApp().globalData.AddClientUrl("/fx_center.html");
      var that = this; 
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          if (res.errMsg == 'request:ok') {
            let fxCenter = res.data;
            that.getMembersListData(fxCenter)
            that.setData({
              fxCenter: fxCenter
            });
          }
          if (res.data.errcode == '10001') {
            that.setData({
              fxCenter: null
            });
          }
          console.log("====get_fx_center===", res);
          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
      getMembersListData: function (fxCenter) {
        let that = this;
        let customIndex = getApp().globalData.AddClientUrl("/wx_find_user_levels.html");
        wx.request({
          url: customIndex.url,
          header: getApp().globalData.header,
          success: function (res) {
            console.log('====getUserCardPackage-res===', res,fxCenter);
            if (res.data.errcode == 0) {
              let data = res.data.relateObj;
              if(data.length!=0){
                  for (let i = 0; i < data.length; i++){
                      if(fxCenter.userLevel==data[i].levelValue){
                        that.setData({
                          fxState: true,
                          myMembers: data[i]
                        });
                        break;
                      }
                  }
              }else{
                that.setData({
                  fxState: false
                });
                that.tip();
              }
            } else {
              wx.showModal({
                title: '提示',
                content: '主人~请求超时！确认重新加载',
                success: function (res) {
                  if (res.confirm) {
                  } else if (res.cancel) {
                    console.log('用户点击取消');
                  }
                }
              });
            }
          },
          complete: function (res) {}
        });
      },
    tip: function (tipText) {
      wx.showModal({
        title: '提示',
        content: tipText || '主人~您还没有分销权限哦!',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定');
            getApp().globalData.toIndex();
          } else if (res.cancel) {
            console.log('用户点击取消');
            getApp().globalData.toIndex();
          }
        }
      });
    },
    // 这里是一个自定义方法
    calling: function (e) {
      console.log('====e===', e);
      let phoneNumber = e.currentTarget.dataset.phonenumber;
      wx.makePhoneCall({
        phoneNumber: phoneNumber,
        success: function () {
          console.log("拨打电话成功！");
        },
        fail: function () {
          console.log("拨打电话失败！");
        }
      });
    },
    //获取推广中心，查看是否有资格
    get_fx_detailFun: function (setting) {
      console.log('-------推广中心--------');
      var customIndex = getApp().globalData.AddClientUrl("/wx_get_fx_data.html");
      var that = this; 
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("===get_fx_detail===", res);
          if (res.data.errcode == '0') {
            let fxDetail = res.data.relateObj;
            that.setData({
              fxDetail: fxDetail
            });
            if(fxDetail.fxSetting.profitPool){
                that.getTongji(fxDetail.fxSetting.profitPool)
            }
          }

          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    //获取推广中心，查看是否有资格
    getTongji: function (profitPool) {
      console.log('-------推广中心--------');
      let that=this;
      that.showState=false;
      that.showHeight="55rpx";
      that.showCount=1;
      that.maxCount=1;
      let profitPoolArr=JSON.parse(profitPool);
      let targetIdArr=[];
      let showPoolProfitList=[];
      let maxCount=0
      for(let i=0;i<profitPoolArr.length;i++){
          targetIdArr.push(profitPoolArr[i].poolId);
          if(profitPoolArr[i].showState==1){
              maxCount++
          }
      }
      that.maxCount=maxCount
      let time=that.getNowTime('rail')+'-01';
      console.log("===time===",time)
      let params={
          targetIds:targetIdArr.join(","),
          dateStr:time,
          pageSize:targetIdArr.length,
      }
      var customIndex = getApp().globalData.AddClientUrl("/wx_find_target_month_tongji.html", params, 'get');
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("===getTongji===", res);
          if (res.data.errcode == '0'&&res.data.relateObj.result) {
              let poolProfitList=res.data.relateObj.result;
              for(let i=0;i<poolProfitList.length;i++){
                  for(let j=0;j<profitPoolArr.length;j++){
                      if(poolProfitList[i].tongjiTargetId==profitPoolArr[j].poolId){
                          poolProfitList[i].showState=profitPoolArr[j].showState
                      }
                  }
                  poolProfitList[i].month=String(poolProfitList[i].month).length==1?"0"+poolProfitList[i].month:poolProfitList[i].month
              }
              for(let k=0;k<poolProfitList.length;k++){
                  if(poolProfitList[k].showState==1){
                      showPoolProfitList.push(poolProfitList[k])
                  }
              }
              that.setData({
                  poolProfitList:poolProfitList,
                  showPoolProfitList:showPoolProfitList
                })
          }
          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
      getNowTime:function(type){
        let date = new Date();
        let seperator1 = "-";
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        let currentdate = year + seperator1 + month ;
        if(type=='text'){
            currentdate = year +'年' + month +'月';
        }
        return currentdate;
      },
    // 关闭海报
    getChilrenPoster:function(e) {
      let that = this;
      that.setData({
        posterState: false
      });
    },
    showPoster: function () {
      let that = this;
      console.log('===showPoster====', that.loginUser.id);

      if (that.loginUser && that.loginUser.platformUser.id) {
        let ewmImgUrl = getApp().globalData.getQrCode({
          type: "user_info",
          id: that.loginUser.platformUser.id
        });
        that.setData({
          posterState: true,
          ewmImgUrl: ewmImgUrl
        });
      } else {
        wx.showModal({
          title: '提示',
          content: '您还未登录，点击【确定】重新加载',
          success: function (res) {
            if (res.confirm) {
              that.getSessionUserInfo();
            } else if (res.cancel) {}
          }
        });
      }
    },
    getSessionUserInfo: function () {
      var that = this;
      var postParamUserBank = getApp().globalData.AddClientUrl("/get_session_userinfo.html");
      wx.request({
        url: postParamUserBank.url,
        data: postParamUserBank.params,
        header: getApp().globalData.headerPost,
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            that.setData({
              loginUser: res.data.relateObj
            });
            that.getMembersListData(res.data.relateObj)
            getApp().globalData.loginUser = res.data.relateObj;
          } else {
            getApp().globalData.loginUser = null;
            that.loginUser=null;
            that.myMembers=null
            wx.showToast({
              title: res.data.errMsg,
              image: '/wxcomponents/images/icons/tip.png',
              duration: 1000
            });
          }
        },
        fail: function (res) {
          console.log(res.data);
        },
        complete: function (res) {
          wx.stopPullDownRefresh();
        }
      });
    },
    loginSuccess: function (user) {
      console.log("pre apply mendian login success call back!", user);
      this.checkState();
    },
    loginFailed: function (err) {
      console.log("login failed!!");
    },
    checkState: function () {
      let that = this;
      console.log('======checkState.loginUser======', getApp().globalData.loginUser,getApp().globalData.setting);
      that.setData({
        loginUser: getApp().globalData.loginUser
      });
      let sendFormData = JSON.stringify({
        title: 'noTitle',
        url: "fx_center"
      });
      that.setData({
        sendFormData: sendFormData
      });
      console.log("sendFormData", sendFormData);
      wx.setNavigationBarColor({
        frontColor: getApp().globalData.setting.platformSetting?getApp().globalData.setting.platformSetting.topColor.toLowerCase():'',
        backgroundColor: getApp().globalData.setting.platformSetting?getApp().globalData.setting.platformSetting.topBgColor:''
      });
      that.get_fx_centerFun(getApp().globalData.setting);
      that.get_fx_detailFun();
      that.get_fxLevelFun(getApp().globalData.setting);
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style scoped>
@import "./index.css";
</style>